/*
 * TestDumpCPPCondExp.c
 *
 *  Created on: 2012/05/31
 *      Author: guanxiaoying
 */
#include "TestDump.h"

static VOID dumpPPCondExp( AST astPPCond ){
	AST codescp = CPPCondExp.getCodeScp(astPPCond);

	sprintf( tempBuf, header_format, dumpGetStr(XML_RECORD), astPPCond );
	dumpOutputStream( tempBuf );

	dumpCodeScopeAsField( codescp );

	sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_KIND), "" );
	dumpOutputStream( tempBuf );
	dumpParameterStr( CPPOutput.CPPCondExpKind->CppGetOpLabel( CPPCondExp.getOperatorKind(astPPCond) ) );
	sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_KIND)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_PPCONDEXP), "left",
			CPPCondExp.getLeftNode((astPPCond)));
	dumpOutputStream( tempBuf );
	sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_PPCONDEXP)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, sub_tab_header_format, dumpGetStr(XML_PPCONDEXP), "right",
			CPPCondExp.getRightNode((astPPCond)));
	dumpOutputStream( tempBuf );
	sprintf( tempBuf, sub_tab_tail_format, dumpGetStr(XML_PPCONDEXP)  );
	dumpOutputStream( tempBuf );

	if( CPPCondExp.isTypeDouble( astPPCond )){
		DOUBLE value = CPPCondExp.getValueofDouble( astPPCond );
		sprintf( constantBuffer, "%f", value  );
	}else if( CPPCondExp.isTypeSigned( astPPCond )){
		S4 value = CPPCondExp.getValueofsigned( astPPCond );
		sprintf( constantBuffer, "%ld", value  );
	}else{
		U4 value = CPPCondExp.getValueofUnsigned( astPPCond );
		sprintf( constantBuffer, "%lu", value  );
	}
	sprintf( tempBuf, sub_value_header_format, dumpGetStr(XML_VALUE), "");
	dumpOutputStream( tempBuf );
	dumpParameterStr( constantBuffer );
	sprintf( tempBuf, sub_value_tail_format, dumpGetStr(XML_VALUE)  );
	dumpOutputStream( tempBuf );

	sprintf( tempBuf, tail_format, dumpGetStr(XML_RECORD) );
	dumpOutputStream( tempBuf );
}
VOID DumpPPCondExp( PSZ szPath, PSZ postfix ){
	AST astPPCond;
	AST astMax = CPPOutput.CPPCondExp->getMax();
	if( szPath == NULL ){
		return;
	}
	strcpy( file_buf, szPath );
	file_buf[strlen(szPath)] = '\0';
	strcat(file_buf, postfix );
	file_buf[strlen(szPath)+strlen(postfix)] = '\0';
	if( COEXIT_SUCCESS == dumpOutputStreamInit_file(file_buf)){
		sprintf( tempBuf, top_header, dumpGetStr(XML_PPCONDEXP) );
		dumpOutputStream( tempBuf );
		for( astPPCond = MIN_ARRAY; astPPCond <= astMax; astPPCond++ ){
			dumpPPCondExp( astPPCond );
		}
		sprintf( tempBuf, top_end, dumpGetStr(XML_PPCONDEXP) );
		dumpOutputStream( tempBuf );
		dumpOutputStreamEnd_file();
	}
}

